﻿package view.popup.control
{
    import com.greensock.*;
    import com.sh.game.global.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.roleN.model.*;
    import pluginfw.nio.*;
    import uiresource.popup.*;
    import view.light.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class YiJianHuanZhuang extends HdUI implements IDialogUI
    {
        private var level:int = 0;
        private var timeline:TweenMax;
        private var _timeID:uint;
        private var calltime:int = 5;

        public function YiJianHuanZhuang()
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this.initEvent();
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            this.visible = false;
            LightFactory.showlight(btn_genghuan);
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Up, TweenVisibleManager.Auto);
            return;
        }// end function

        protected function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            TweenVisibleManager.instance.register(this, TweenVisibleManager.Up, TweenVisibleManager.Auto);
            return;
        }// end function

        private function initEvent() : void
        {
            btn_genghuan.addEventListener(MouseEvent.CLICK, this.btn_genghuanHandler);
            btn_close.addEventListener(MouseEvent.CLICK, this.btn_closeHandler);
            return;
        }// end function

        protected function btn_closeHandler(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        protected function btn_genghuanHandler(event:MouseEvent) : void
        {
            this.clearTime();
            var _loc_2:* = new Output();
            _loc_2.writeVarInt(this.level, false);
            PluginManager.instance.sendToBufferServer("role", CMDRole.YiJianHuanZhuangREQ, _loc_2);
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.level = int(param1.level);
            var _loc_2:* = ConfigDictionary.data.allarmput[this.level];
            var _loc_3:* = ItemUilt.getBoxArr(_loc_2.boxid);
            list.array = _loc_3;
            list.renderHandler = new Handler(this.listrHandler);
            TweenVisibleManager.instance.changevisible(this, true);
            this.playEmail();
            this.clearTime();
            this._timeID = setInterval(this.readtime, 1000);
            return;
        }// end function

        private function clearTime() : void
        {
            if (this._timeID > 0)
            {
                clearInterval(this._timeID);
                this._timeID = 0;
                this.calltime = 5;
            }
            return;
        }// end function

        private function readtime() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this.calltime - 1;
            _loc_1.calltime = _loc_2;
            btn_genghuan.label = "更换(" + this.calltime + ")";
            if (this.calltime <= 0)
            {
                this.btn_genghuanHandler(null);
            }
            return;
        }// end function

        private function listrHandler(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = param1.dataSource;
            }
            return;
        }// end function

        public function close() : void
        {
            TweenVisibleManager.instance.changevisible(this, false);
            this.stopEmail();
            return;
        }// end function

        public function playEmail() : void
        {
            if (this.timeline)
            {
                this.timeline.kill();
            }
            btn_genghuan.filters = [];
            this.timeline = TweenMax.to(btn_genghuan, 1, {glowFilter:{color:16763904, alpha:1, blurX:6, blurY:6, strength:4}, repeat:int.MAX_VALUE, yoyo:true});
            return;
        }// end function

        public function stopEmail() : void
        {
            if (this.timeline)
            {
                this.timeline.kill();
            }
            btn_genghuan.filters = [];
            return;
        }// end function

    }
}
